<html>
<head>
  <style>
    table { border:1px solid black; border-spacing:-1px; }
    th,td { border:1px solid black; padding:3px; }
  </style>  
  <script type="text/tiscript">
    
  include "sqlite.tis";
    
  event click $(#test)
  {  
    var db = SQLite.open(":memory:"); // in memory, temporary DB
           //DB.open("c:/test.db");
        db.exec("CREATE TABLE stocks (key INTEGER PRIMARY KEY, date TEXT, trans TEXT, symbol TEXT, qty REAL, price REAL);" );
        
        // as a string   
        db.exec("insert into stocks values (NULL,'2006-01-05','BUY','RHAT',100,35.14)" );
        db.exec("insert into stocks values (NULL,'2006-01-05','BUY','BANT',10,5.23)" );
        // with params:
        db.exec("insert into stocks values (NULL,?,?,?,?,?)", ["2006-04-05", "BUY", "MSOFT", 1000, 72.00] );
    
        var [r,recordsAffected] = db.exec("insert into stocks values (NULL,?,?,?,?,?)", ["2006-04-06", "SELL", "IBM", 500, 53.00] );
        
        $(#result).text = String.printf("result=%d, recordsAffected=%d",r,recordsAffected);

        var rs = db.exec("select * from stocks order by price");
        if ( SQLite.isRecordset(rs) )
          showRecordset(rs);
        else
          $(#result).text = "Wrong type:" + rs;

        showSchema(db);  
        db.close();
  }
  
  function showRecordset(rs)
  {
    $(body).append(SQLite.tableFrom(rs));
  }
  function showSchema(db)
  {
    const body = $(body);
    body.append(<caption>Tables:</caption>);
    body.append(<pre>{JSON.stringify(SQLite.tablesIn(db))}</pre>);
    body.append(<caption>Indexes:</caption>);
    body.append(<pre>{JSON.stringify(SQLite.indexesIn(db))}</pre>);
  }

  </script>  
</head>
<body>
  <button #test>Test it</button>
  <text #result />
</body>
</html>